/**
 * Created by koudaiwang on 2017/6/20.
 */


var User = require('./dao').User;
module.exports = {

    addUser: function create(user) {
        user['nickname'] = '';
        user['avatar'] = '';
        user['gender'] = 'x';
        user['bio'] = '';
        user['score'] = 0;
        user['webLogin'] = '';
        user['webLoginTime'] = '';
        user['iOSLogin'] = '';
        user['iOSLoginTime'] = '';
        user['androidLogin'] = '';
        user['androidLoginTime'] = '';
        return User.create(user).exec();
    },

    delUser: function (userName) {
        var query = {};
        if (userName) {
            query.userName = userName;
        }
        return User.remove(query).exec();
    },

    getUserByName: function (userName) {
        var query = {};
        if (userName) {
            query.username = userName;
        }
        return User.find(query).sort({ _id: -1 }).exec();
    },
    updateLoginStatus: function (userID, data) {
        return User.update({ _id: userID }, { $set: data }).exec();
    }
};